/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package serverside;

import java.io.*;
import java.net.*;
import server.network.ServerNetwork.ServerTask;
/**
 *
 * @author TuyetNgan
 */
public class ControlServerSide implements Runnable {
        
    private static Integer portControl = 1999;
    private static ServerTask peerOnline[]; 
    private static ServerTask peerDataTransfer[]; 
    private static Integer maxPeerService = 10;
    public ControlServerSide(){}
    @Override
        public  void run() {
        // TODO code application logic here
    
          peerOnline = new ServerTask[maxPeerService];
          try {
                ServerSocket serverSocket = null;
                boolean listening = true;
                int count = 0;
                try {
                    serverSocket = new ServerSocket(portControl);
                } catch (IOException e) {
                    System.err.println("Could not listen on port: " + portControl);
                    System.exit(-1);
                }
                System.out.println("Server start control port!");
                while (listening){
                    (peerOnline[count] = new ServerTask(serverSocket.accept(),count,peerOnline)).start();
                    count++;
                }
                serverSocket.close();
            } catch (IOException e){}
      
        }
	}